#pragma once
#include <iostream>
using namespace std;
#include <string>
#include "util.hpp"
#include <sstream>


const string default_root = "wwwroot/";
const string home_page = "index.html";

class httpRequest
{
public:
    httpRequest()
    {
    }

    ~httpRequest()
    {
    }

    void parse()
    {
        // 1:从inbuffer中拿到第一行，分隔符\r\n
        string line = util::getOneline(inbuffer);
        // 2:从请求行中拿到3个字段

        cout << "line:" << line << endl;
        stringstream ss(line); // 按空格进行分割
        ss >> method >> url >> httpversion;

        // 3:添加web默认路径
        path = default_root;
        path += url;
        if (path[path.size() - 1] == '/')
            path += home_page;
    }

public:
    string inbuffer;

    string method;
    string url;
    string httpversion;

    string path;
};

class httpResponse
{
public:
    string outbuffer;
};